package com.prs.crm.domain.sale;

import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.Cascade;

import com.prs.crm.domain.FlowCodeEntity;

@Entity
@Table(name = "sale_returns")
public class Returns extends FlowCodeEntity {

	private static final long serialVersionUID = 1L;

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private Integer id;

	/**
	 * 合同
	 */
	@ManyToOne
	private SalesContract salesContract;
	/**
	 * 关联发货单
	 */
	@ManyToOne
	private SalesShipping salesShipping;

	/**
	 * 退货编号
	 */
	private String returnCode;
	/**
	 * 退货主题
	 */
	private String returnName;
	/**
	 * 退货日期
	 */
	private Date returnDate;
	/**
	 * 退货分类
	 */
	@ManyToOne
	private ReturnsType returnType;
	/**
	 * 退货状态
	 */
	private String returnState;
	/**
	 * 退货明细
	 */
	@OneToMany(mappedBy = "returns")
	@Cascade( { org.hibernate.annotations.CascadeType.ALL,
			org.hibernate.annotations.CascadeType.DELETE_ORPHAN })
	private Set<ReturnsDetail> details;
	/**
	 * 退货原因
	 */
	@Lob
	private String returnCause;

	// @OneToOne(fetch=FetchType.LAZY,mappedBy="returns")
	// private Code code;
	/**
	 * 付钱状态
	 */
	@Column(columnDefinition = "Integer(2) default '0'")
	private int moneyType;

	public int getMoneyType() {
		return moneyType;
	}

	public void setMoneyType(int moneyType) {
		this.moneyType = moneyType;
	}

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getReturnCode() {
		return returnCode;
	}

	public void setReturnCode(String returnCode) {
		this.returnCode = returnCode;
	}

	public String getReturnName() {
		return returnName;
	}

	public void setReturnName(String returnName) {
		this.returnName = returnName;
	}

	public Date getReturnDate() {
		return returnDate;
	}

	public void setReturnDate(Date returnDate) {
		this.returnDate = returnDate;
	}

	public ReturnsType getReturnType() {
		return returnType;
	}

	public void setReturnType(ReturnsType returnType) {
		this.returnType = returnType;
	}

	public String getReturnState() {
		return returnState;
	}

	public void setReturnState(String returnState) {
		this.returnState = returnState;
	}

	public Set<ReturnsDetail> getDetails() {
		return details;
	}

	public void setDetails(Set<ReturnsDetail> details) {
		this.details = details;
	}

	public String getReturnCause() {
		return returnCause;
	}

	public void setReturnCause(String returnCause) {
		this.returnCause = returnCause;
	}

	public void addDetail(ReturnsDetail detail) {
		if (details == null)
			details = new HashSet<ReturnsDetail>();
		detail.setReturns(this);
		details.add(detail);
	}

	public SalesShipping getSalesShipping() {
		return salesShipping;
	}

	public void setSalesShipping(SalesShipping salesShipping) {
		this.salesShipping = salesShipping;
	}

	public SalesContract getSalesContract() {
		return salesContract;
	}

	public void setSalesContract(SalesContract salesContract) {
		this.salesContract = salesContract;
	}

	// public Code getCode() {
	// return code;
	// }
	//
	// public void setCode(Code code) {
	// this.code = code;
	// }

}
